from django.db import models

####################### 以下是景点预约系统的表格 ############################
'''用户表'''
class User(models.Model):
    username = models.CharField(verbose_name="用户名", max_length=16)
    password = models.CharField(verbose_name="密码", max_length=64)
    email = models.CharField(verbose_name="邮箱", max_length=64)
    phone = models.CharField(verbose_name="手机号", max_length=20)
    gender_choices = (
        (1, "男"),
        (2, "女"),
    )
    gender = models.SmallIntegerField(verbose_name="性别", choices=gender_choices, default=1)
    def __str__(self):
        return self.username

'''管理员表'''
class Admin(models.Model):
    adminname = models.CharField(verbose_name="管理员名", max_length=16)
    password = models.CharField(verbose_name="密码", max_length=64)


'''景点表'''
class Scenic(models.Model):
    """ 城市 """
    sname = models.CharField(verbose_name="景点名称", max_length=32)
    # 本质上数据库也是CharField，自动保存数据。
    image = models.FileField(verbose_name="景点图片", max_length=128, upload_to='scenic/')
    introduce = models.CharField(verbose_name="景点简介", max_length=255)
    price = models.DecimalField(verbose_name="景点价格", max_digits=10, decimal_places=2, default=0)
    level_choices = (
        (1, "A级"),
        (2, "AA级"),
        (3, "AAA级"),
        (4, "AAAA级"),
        (5, "AAAAA级"),
    )
    level = models.SmallIntegerField(verbose_name="A等级", choices=level_choices, default=1)
    tricknum = models.IntegerField(verbose_name="门票数量", default=100)
    province = models.CharField(verbose_name="省份", max_length=10)
    opentime = models.CharField(verbose_name="开放时间", max_length=100)
    bookcount = models.IntegerField(verbose_name="预约数量", default=1)
    def __str__(self):
        return self.sname

    def __str__(self):
        return self.image


'''预约信息表'''
class Bookinfo(models.Model):
    """ 城市 """
    bookname = models.CharField(verbose_name="预约姓名", max_length=32)
    email = models.CharField(verbose_name="邮箱", max_length=64)
    phone = models.CharField(verbose_name="手机号", max_length=20)
    booktime = models.DateField(verbose_name="预约时间")
    type_choices = (
        (1, "成人票"),
        (2, "儿童票"),
    )
    type = models.SmallIntegerField(verbose_name="门票类型", choices=type_choices, default=1)
    description = models.CharField(verbose_name="备注", max_length=255)
    subtime = models.DateField(verbose_name="提交时间")
    uid = models.ForeignKey(to="User", to_field="id", on_delete=models.CASCADE, verbose_name="用户ID")
    sceid = models.ForeignKey(to="Scenic", to_field="id", on_delete=models.CASCADE, verbose_name="景点ID")


'''留言信息表'''
class Message(models.Model):
    """ 城市 """
    messagename = models.CharField(verbose_name="留言姓名", max_length=32)
    subject = models.CharField(verbose_name="科目", max_length=255)
    email = models.CharField(verbose_name="邮箱", max_length=64)
    phone = models.CharField(verbose_name="手机号", max_length=20)
    context = models.CharField(verbose_name="留言内容", max_length=255, default="")
    reply_choices = (
        (1, "未回复"),
        (2, "已回复"),
    )
    reply = models.SmallIntegerField(verbose_name="回复状态", choices=reply_choices, default=1)
    user = models.ForeignKey(to="User", to_field="id", on_delete=models.CASCADE, verbose_name="用户ID")

'''图片表'''
class ImageList(models.Model):
    """ 城市 """
    imagename = models.CharField(verbose_name="景点名称", max_length=32)
    # 本质上数据库也是CharField，自动保存数据。
    image = models.FileField(verbose_name="景点图片", max_length=128, upload_to='scenic/')
    image_choices = (
        (1, "轮播图"),
        (2, "后台首页"),
    )
    level = models.SmallIntegerField(verbose_name="图片使用场景", choices=image_choices, default=2)
    description = models.CharField(verbose_name="备注", max_length=32, blank=True)


# class Comments(models.Model):
#     # 景区id
#     # scenic = models.ForeignKey(to='Scenic',to_field='ID',null=True,blank=True,on_delete=models.SET_NULL)
#     scenic = models.ForeignKey(to='Scenic',to_field='ID',on_delete=models.CASCADE)
#     # 用户id
#     user=models.ForeignKey(to='User',to_field='ID',on_delete=models.CASCADE())
#     # 评论内容
#     Commentscontent=models.CharField(verbose_name="景点名称", max_length=999)

